package com.lxmes.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.lxmes.common.annotation.RepeatSubmit;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import com.lxmes.business.domain.PsYhPlan;
import com.lxmes.business.service.IPsYhPlanService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;

/**
 * 要货计划Controller
 * 
 * @author 张志煜
 * @date 2023-03-21
 */
@RestController
@RequestMapping("/business/psYhPlan")
public class PsYhPlanController extends BaseController
{
    @Autowired
    private IPsYhPlanService psYhPlanService;

    /**
     * 查询要货计划列表
     */
    @PreAuthorize("@ss.hasPermi('business:psYhPlan:list')")
    @GetMapping("/list")
    public TableDataInfo list(PsYhPlan psYhPlan)
    {
        startPage();
        List<PsYhPlan> list = psYhPlanService.selectPsYhPlanList(psYhPlan);
        return getDataTable(list);
    }

    /**
     * 导出要货计划列表
     */
    @PreAuthorize("@ss.hasPermi('business:psYhPlan:export')")
    @Log(title = "要货计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PsYhPlan psYhPlan)
    {
        List<PsYhPlan> list = psYhPlanService.selectPsYhPlanList(psYhPlan);
        ExcelUtil<PsYhPlan> util = new ExcelUtil<PsYhPlan>(PsYhPlan.class);
        util.exportExcel(response, list, "要货计划数据");
    }
    /*查询需要新增的要货计划*/
    @GetMapping("/getAddPsYhPlanList")
    public AjaxResult getAddPsYhPlanList(PsYhPlan psYhPlan)
    {
        List<PsYhPlan> list = psYhPlanService.getAddPsYhPlanList(psYhPlan);
        return AjaxResult.success(list);
    }
    @PostMapping("/addPsYhPlanList")
    @Log(title = "要货计划", businessType = BusinessType.INSERT)
    @RepeatSubmit
    public AjaxResult addPsYhPlanList(@RequestBody List<PsYhPlan> planList)
    {
        return toAjax(psYhPlanService.insertPsYhPlanList(planList));
    }



    /**
     * 获取要货计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:psYhPlan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(psYhPlanService.selectPsYhPlanById(id));
    }

    /**
     * 新增要货计划
     */
    @PreAuthorize("@ss.hasPermi('business:psYhPlan:add')")
    @Log(title = "要货计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PsYhPlan psYhPlan)
    {
        return toAjax(psYhPlanService.insertPsYhPlan(psYhPlan));
    }

    /**
     * 修改要货计划
     */
    @PreAuthorize("@ss.hasPermi('business:psYhPlan:edit')")
    @Log(title = "要货计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PsYhPlan psYhPlan)
    {
        return toAjax(psYhPlanService.updatePsYhPlan(psYhPlan));
    }

    /**
     * 删除要货计划
     */
    @PreAuthorize("@ss.hasPermi('business:psYhPlan:remove')")
    @Log(title = "要货计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(psYhPlanService.deletePsYhPlanByIds(ids));
    }
}
